package com.syqc.monitor.popup

import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.TextView
import androidx.core.view.isVisible
import com.syqc.comlib.UserConstant
import com.syqc.monitor.R
import com.syqc.monitor.databinding.PopupMapMoreBinding


/** @Author Jasper @Time 2020/10/29 @Desc todo */
class MapMorePopup(context: Context) :
    PopupWindow() {
    private val binding: PopupMapMoreBinding by lazy {
        PopupMapMoreBinding.inflate(
            LayoutInflater.from(
                context
            )
        )
    }

    init {
        contentView = binding.root
        isFocusable = true //popupwindow设置焦点
        setBackgroundDrawable(ColorDrawable(0)) //设置背景
//        isOutsideTouchable = true //点击外面窗口消失
        width = LinearLayout.LayoutParams.WRAP_CONTENT //设置SelectPicPopupWindow弹出窗体的宽
        height = LinearLayout.LayoutParams.WRAP_CONTENT //设置SelectPicPopupWindow弹出窗体的高
        initView()
    }

    private var listener: View.OnClickListener? = null

    fun setViewClickListener(listener: View.OnClickListener?) {
        this.listener = listener
    }


    private fun initView() {
        binding.tvPopupClearAll.setOnClickListener {
            listener?.onClick(it)
        }
//        binding.tvPopupRefresh.setOnClickListener {
//            listener?.onClick(it)
//        }
        binding.tvShowPopup.setOnClickListener {
            listener?.onClick(it)
        }
        binding.tvPopupAllCars.setOnClickListener {
            listener?.onClick(it)
        }
        binding.tvPopupNamePlate.setOnClickListener {
            listener?.onClick(it)
        }
        binding.tvPopupCluster.setOnClickListener {
            listener?.onClick(it)
        }

        if (UserConstant.current_car_num > 300) {
            binding.tvPopupCluster.isVisible = false
            binding.tvPopupAllCars.isVisible = false
        }
    }

    fun setCluster(isCluster: Boolean) {
        if (isCluster) binding.tvPopupCluster.setText(R.string.desc_popup_cluster_open)
        else binding.tvPopupCluster.setText(R.string.desc_popup_cluster_close)
        binding.tvPopupCluster.isSelected = isCluster
    }

    fun setPopupShow(isShow: Boolean) {
        binding.tvShowPopup.isSelected = isShow
    }

    //设置是否显示聚合
    fun setShowCluster(isVisibility: Boolean) {
        binding.tvPopupCluster.isVisible = isVisibility
    }

}

